/**
 * Module:  Data
 * File:    data.js
 * Author:  Vlad Andreev <php.vlad@gmail.com>
 **/


function data_type_delete(id) {
    
    var delete_table = ($('#Data_delete_table_'+ id).attr('checked')) ? 1 : 0;
    
    $.ajax({
        type: 'post',
        url:  '/Data/delete/DataType/'+ id,
        data: 'theme_control=true&delete_table='+ delete_table,
        complete: function (data) {
	    
	    if (data['responseText'] == '') {
		
		acLoadPage();
		acLoadOptions();
	    } else {
		
		alert(data['responseText']);
	    }
	}
    });
}

function data_field_add(data_name) {
    
    var fields = new Array('name', 'title', 'type', 'data_name', 'active', 'module');
    var data   = new Array();                    				// массив со значениями этих параметров
    
    for (i=0; i<fields.length; i++)
	data.push(fields[i] +'='+ acHtmlValue('Data_'+ fields[i]));
    
    data.push('theme_control=true');
    
    $.ajax({
	dataType: 'json',
        type: 'post',
        url: '/Data/save/DataField',
        data: data.join('&'),
	success: function(data) {
	    if(checkStatus(data)) {
		
		acLoadPage()
		acLoadOptions();
		
		if (data && data.message)
		    alert(data.message);
	    }
	},
	
    });
}

function data_field_edit(data_name, id, redirect) {
    
    var fields = new Array('name', 'title', 'type');				// массив с полями
    var data   = new Array();            					// массив со значениями
    
    for (i=0; i<fields.length; i++)
	data.push(fields[i] +'='+ acHtmlValue(data_name +'_'+ fields[i] +'_'+ id));
    
    data.push('theme_control=true');
    
    $.ajax({
	dataType: 'json',
        type: 'post',
        url:  '/Data/save/DataField/'+ id,
        data: data.join('&'),
	success: function(data) {
	    if(checkStatus(data)) {
		
		if (redirect && redirect != '')
		    location.href = '#Data/'+ redirect;
		else
		    acLoadOptions();
		
		if (data && data.message)
		    alert(data.message);
	    }
	},
    });
}
